class Solution {//leetcode34——在排序数组中查找第一个和最后一个位置
private:

public:
    vector<int> searchRange(vector<int>& nums, int target) {
        if(nums.size()==0) return {-1,-1};
        int begin=0,end=nums.size()-1;
        int left,right;
        for(left=begin,right=end;left<right;){//寻找左端点
            int mid=left+(right-left)/2;
            if(nums[mid]>=target)right=mid;
            else left=mid+1;
        }
        if(nums[left]==target) begin=left;
        else return vector<int>{-1,-1};
        for(left=begin,right=end;left<right;){
            int mid=left+(right-left+1)/2;
            if(nums[mid]<=target) left=mid;
            else right=mid-1;
        }
        if(nums[right]==target) end=right;
        return vector<int>{begin,end};
    }
};